# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者：cacho_37967865
#博客：https://blog.csdn.net/sinat_37967865
#文件：python_operator.py
#日期：2019-09-03
#备注：Python中内置的%操作符可用于格式化字符串操作，控制字符串的呈现格式  
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


print ('字符串 (采用str()的显示)：',"His name is %s"%("Aviad"))  # Aviad

print ('字符串 (采用repr()的显示)：',"His name is %r"%("Aviad"))   # "Aviad"

print ('十进制整数：',"He is %d years old"%(25.8))      # 25

print ('浮点数f：',"His height is %f m"%(1.839))         # 1.839000

print ('浮点数F：',"His height is %F m"%(1.839))         # 1.839000

print ('打印浮点数（指定保留小数点位数）：',"His height is %.3f m"%(1.8365))  # 1.84

print ('指定占位符宽度：',"Name:%2s Age:%4d Height:%6.2f"%("Aviad",25,1.833))

print ('指定占位符宽度（左对齐）：',"Name:%-10s Age:%-8d Height:%-8.2f"%("Aviad",25,1.833))

print ('指定占位符,补齐0：',"Name:%-10s Age:%03d Height:%03.2f"%("Aviad",25,1.83))      # %03d

print('科学计数法：',format(0.0015,'.2e'))

print ('用词典来传递真实值：',"I'm %(c)s. I have %(l)d yuan." % {'c':'hungry','l':22})

print ('用format来传递真实值：',"I'm {0}. I have {1} yuan.".format('hungry',22))
